package com.dengyafei.controller;

import com.dengyafei.annotation.JwtToken;
import com.dengyafei.bean.PropagandaEntity;
import com.dengyafei.constant.RecommendConstant;
import com.dengyafei.constant.ResultMessage;
import com.dengyafei.domin.vo.*;
import com.dengyafei.result.RestApiResult;
import com.dengyafei.service.PropagandaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 邓亚非
 */
@RestController
@RequestMapping(value = "/propaganda")
@Slf4j
public class PropagandaController {

    @Autowired
    PropagandaService propagandaService;

    /**
     * 根据hid查询宣讲会
     *
     * @return
     */
    @JwtToken
    @PostMapping(value = "/queryAllPropagandaByHid")
    public RestApiResult queryAllPropagandaByHid() {
        log.info("【校园宣讲模块-hid查询宣讲会接口-无参】:[{}]", "无参");
        List<PropagandaEntity> propagandaEntities = propagandaService.queryAllPropagandaByHid();
        log.info("【校园宣讲模块-hid查询宣讲会接口-成功】:[{}]", ResultMessage.Propaganda.QUERY_SUCCESS);
        return RestApiResult.ok(propagandaEntities);
    }

    /**
     * 条件查询
     *
     * @param propagandaSearchVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/searchByParams")
    public RestApiResult searchByParams(@RequestBody PropagandaSearchVO propagandaSearchVO) {
        log.info("【校园宣讲模块-条件查询宣讲会接口-参数】propagandaSearchVO:[{}]", propagandaSearchVO);
        List<PropagandaEntity> propagandaEntities = propagandaService.queryByParams(propagandaSearchVO);
        log.info("【校园宣讲模块-条件查询宣讲会接口-成功】:[{}]", ResultMessage.Propaganda.QUERY_SUCCESS);
        return RestApiResult.ok(propagandaEntities);
    }

    /**
     * 添加宣讲会
     *
     * @param propagandaAddVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/add")
    public RestApiResult add(@RequestBody PropagandaAddVO propagandaAddVO) {
        log.info("【宣讲会模块-添加接口-参数】propagandaAddVO:[{}]", propagandaAddVO);
        Integer integer = propagandaService.insertPropaganda(propagandaAddVO);
        if (!integer.equals(RecommendConstant.OPERATION_SUCCESS)) {
            log.error("【宣讲会模块-添加接口-失败】propagandaAddVO,cause:[{}]", ResultMessage.Propaganda.ADD_FAILURE);
            return RestApiResult.error(ResultMessage.Propaganda.ADD_FAILURE);
        }
        log.info("【宣讲会模块-添加接口-成功】propagandaAddVO:[{}]", ResultMessage.Propaganda.ADD_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Propaganda.ADD_SUCCESS);
    }

    /**
     * 查询单个宣讲会
     * @param propagandaQueryVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/queryOnePropaganda")
    public RestApiResult queryOnePropaganda(@RequestBody PropagandaQueryVO propagandaQueryVO){
        log.info("【宣讲会模块-查询单个宣讲会接口-参数】propagandaQueryVO:[{}]",propagandaQueryVO);
        PropagandaEntity propagandaEntity = propagandaService.queryByMid(propagandaQueryVO);
        log.info("【宣讲会模块-查询单个宣讲会接口-成功】propagandaQueryVO:[{}]",ResultMessage.Propaganda.QUERY_SUCCESS);
        return RestApiResult.ok(propagandaEntity);
    }

    /**
     * 更新宣讲会
     * @param propagandaUpdateVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/updatePropaganda")
    public RestApiResult updatePropaganda(@RequestBody PropagandaUpdateVO propagandaUpdateVO){
        log.info("【宣讲会模块-更新宣讲会接口-参数】propagandaUpdateVO:[{}]",propagandaUpdateVO);
        Integer update = propagandaService.update(propagandaUpdateVO);
        if (!update.equals(RecommendConstant.OPERATION_SUCCESS)){
            log.error("【宣讲会模块-更新宣讲会接口-失败】propagandaUpdateVO,cause:[{}]",ResultMessage.Propaganda.UPDATE_FAILURE);
            return RestApiResult.error(ResultMessage.Propaganda.UPDATE_FAILURE);
        }
        log.info("【宣讲会模块-更新宣讲会接口-成功】propagandaUpdateVO:[{}]",ResultMessage.Propaganda.UPDATE_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Propaganda.UPDATE_SUCCESS);
    }

    /**
     * 删除宣讲会
     * @param propagandaDeleteVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/deletePropaganda")
    public RestApiResult deletePropaganda(@RequestBody PropagandaDeleteVO propagandaDeleteVO){
        log.info("【宣讲会模块-删除宣讲会接口-参数】propagandaDeleteVO:[{}]",propagandaDeleteVO);
        Integer delete = propagandaService.delete(propagandaDeleteVO);
        if(!delete.equals(RecommendConstant.OPERATION_SUCCESS)){
            log.error("【宣讲会模块-删除宣讲会接口-失败】propagandaDeleteVO,cause:[{}]",ResultMessage.Propaganda.DELETE_FAILURE);
            return RestApiResult.error(ResultMessage.Propaganda.DELETE_FAILURE);
        }
        log.info("【宣讲会模块-删除宣讲会接口-成功】propagandaDeleteVO:[{}]",ResultMessage.Propaganda.DELETE_SUCCESS);
        return RestApiResult.okMsg(ResultMessage.Propaganda.DELETE_SUCCESS);
    }

    /**
     * 查询所有的宣讲会
     * @return
     */
    @JwtToken
    @PostMapping(value = "loadPropaganda")
    public RestApiResult loadPropaganda(){
        log.info("【宣讲会模块-查询所有的宣讲会接口-参数】:[{}]","无参");
        List<PropagandaEntity> propagandaEntities = propagandaService.queryAll();
        log.info("【宣讲会模块-查询所有的宣讲会接口-成功】:[{}]",ResultMessage.Propaganda.QUERY_SUCCESS);
        return RestApiResult.ok(propagandaEntities);
    }

    /**
     * 条件查询接口
     * @param propagandaSearchVO
     * @return
     */
    @JwtToken
    @PostMapping(value = "/search")
    public RestApiResult search(@RequestBody PropagandaSearchVO propagandaSearchVO){
        log.info("【宣讲会模块-条件查询接口-参数】:[{}]",propagandaSearchVO);
        List<PropagandaEntity> search = propagandaService.search(propagandaSearchVO);
        log.info("【宣讲会模块-条件查询接口-成功】:[{}]",ResultMessage.Propaganda.QUERY_SUCCESS);
        return RestApiResult.ok(search);
    }
}